//--------------------------------------- NOTES ------------------------------------------------------//
* This table is Table A8 in the paper 
//--------------------------------------------------------------------------------------------------------//

cd  "/YOUR_LOCAL_DIRECTORY" //setting the working directory
clear all //remove all data, labels, matrices etc (incl. Mata functions)
use December8ChanRoth, clear

* Create the key treatment variable
gen byte status_quo = treatment=="status_quo"
la var status_quo  "Status Quo"

****** Transplant rate calculation
gen byte transplanted = player2action=="MixWithLowBlue" | player2action=="MixWithHighBlue" | player2action=="MixWithBothBlue"
replace transplanted=2 if player2action=="MixWithBothBlue"


* Create 2 row for each observation
expand 2 if transplanted==2, gen(dupindicator)

* Generate blue ball count variable for transplanted urns
gen tx_urn_blue = player2highbluecount if player2action=="MixWithHighBlue" // blue count for transplanted high blue urn if only high blue transplanted
replace tx_urn_blue = player2lowbluecount if player2action=="MixWithLowBlue" // blue count for transplanted low blue urn if only low blue transplanted
replace tx_urn_blue = player2lowbluecount if player2action=="MixWithBothBlue" // blue count for transplanted low blue urn if both urns transplanted
replace tx_urn_blue = player2highbluecount if player2action=="MixWithBothBlue" & transplanted==2 & dupindicator==1 // blue count for transplanted high blue urn if both urns transplanted

gen byte highballurn = player2action=="MixWithHighBlue" //indicate the "primary" urn considered, 1 for high blue urn
replace highballurn = 1 if player2action=="MixWithBothBlue" & transplanted==2 & dupindicator==1
la var highballurn  "High Blue Urn"

gen status_quoXhighballurn = highballurn*status_quo
la var status_quoXhighballurn  "Status Q*High Blue Urn"

* Did the TC made the patient worse? - a jar that is worse than an urn is mixed into urn
gen byte madeworse2 = player1bluecount<tx_urn_blue

* Generate overall bet odds for TC player (average of tx_urn_blue and jar blue count)
gen tx_bet = (tx_urn_blue+player1bluecount)/2 // Averaging the number of blue balls between jars and urns

* Dummy for low quality kidney getting accepted
gen byte lowQkidneyaccepted = player2action=="MixWithLowBlue" | player2action=="MixWithBothBlue"


* Make table

eststo clear

eststo: quietly reg tx_urn_blue status_quo,  vce(cluster room) // Compare percentage blue of transplanted urns by treatment group
eststo: quietly reg tx_urn_blue status_quo player1bluecount,  vce(cluster room) // Compare percentage blue of transplanted urns by treatment group
eststo: quietly reg tx_bet status_quo,  vce(cluster room) // Compare percentage blue of transplanted urns AFTER MIXING by treatment group
eststo: quietly reg player1bluecount status_quo if transplanted>0,  vce(cluster room) // Compare percentage blue of transplanted jars by treatment group
eststo: quietly reg player1bluecount status_quo if transplanted>0 & madeworse==0,  vce(cluster room) // Compare percentage blue of transplanted jars by treatment group
eststo: quietly reg lowQkidneyaccepted status_quo if dupindicator==0 & player1action=="Offer",  vce(cluster room) // Compare percentage low quality jars accepted by treatment group

label variable player1bluecount "Jar \# Blue Balls"

local numbers "& (1) & (2) & (3) & (4) & (5) & (6) \\ \hline"

*Fix header
esttab using table_transplanted_aggressiveness_a8.tex, se r2  keep(status_quo player1bluecount _cons) star(+ 0.1 * 0.05 ** 0.01) b(3) mgroups("pre-TX Urn \# Blue Balls" "TXed Urn \# Blue Balls" "TXed Jar \# Blue Balls" "\% Low Quality Jars Accepted \(\vert\) offered", pattern(1 0 1 1 0 1) prefix(\multicolumn{@span}{c}{) suffix(}) span) mlabels(none) nonumbers posthead("`numbers'") label title("Differences in Average Number of Blue Balls for Urns (Patients) and Jars (Kidneys) for Those Transplanted and Percentage Low Quality Jars Accepted in Alternative Sample") substitute([htbp] [!htbp] \begin{tabular} \small\begin{tabular} {l} {p{\linewidth}}) addnotes("(Robust, clustered by player-pairings)") stat(N r2, label("N" "\[R^2\]") fmt(a3 %9.3fc))
